package com.bit.dreamer;

import java.util.ArrayList;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class SubMenu extends Activity implements OnClickListener{

	private SharedPreferences sf;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sub_menu);
		
		ActionBar actionbar = getActionBar();
		sf = getSharedPreferences("name", MODE_PRIVATE);
		String nName = sf.getString("name", "");
		actionbar.setTitle(nName + "님 안녕하세요");
		actionbar.setDisplayShowHomeEnabled(false);
		
		ArrayList<Integer> list = new ArrayList<Integer>();
		list.add(R.id.bt_map);
		list.add(R.id.bt_mento);
		list.add(R.id.bt_sk);
		list.add(R.id.bt_sim);
		list.add(R.id.bt_help);
		
		for(int i = 0; i < list.size(); i++) {
			Button btn = (Button)findViewById(list.get(i));
			btn.setOnClickListener(this);
		}
	}

	@Override
	public void onClick(View v) {
		Intent intent = null;
		switch (v.getId()) {
		case R.id.bt_map:
			intent = new Intent(getApplicationContext(), DreamMap.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			break;
			
		case R.id.bt_mento:
			intent = new Intent(getApplicationContext(), MentoActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			break;
			
		case R.id.bt_sk:
			intent = new Intent(getApplicationContext(), SungKyukActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			break;
			
		case R.id.bt_sim:
			intent = new Intent(getApplicationContext(), PsycholActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			break;
			
		case R.id.bt_help:
			intent = new Intent(getApplicationContext(), PrologueActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			break;

		}
		startActivity(intent);
				
	}


	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		
		// Inflate the menu; this adds items to the action bar if it is present.
//		getMenuInflater().inflate(R.menu.lotto_main, menu);
//		return true;
		
		super.onCreateOptionsMenu(menu);
		
		MenuItem item = menu.add(0, 1, 0, "로그인");
		item.setIcon(R.drawable.ic_launcher);
		item.setAlphabeticShortcut('a'); // 키보드 a를 누르면 실행되게끔
		
		menu.add(0, 2, 0, "꿈목록");
		menu.add(0, 3, 0, "꿈등록");
		menu.add(0, 4, 0, "꿈지도");
		
	return true;
	}
	
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch ( item.getItemId()){
		case 1:
			Intent intent1= new Intent(getApplicationContext(), MainActivity.class);
			startActivity(intent1);
			
			Toast.makeText(this, "로그인 화면 가기", Toast.LENGTH_SHORT).show();
			return true;

		case 2 :
			Intent intent2= new Intent(getApplicationContext(), MainMenuActivity.class);
			startActivity(intent2);
			Toast.makeText(this, "나의 꿈 목록 보기", Toast.LENGTH_SHORT).show();
			return true;

		case 3 :
			Intent intent3= new Intent(getApplicationContext(), DreaminsertActivity.class);
			startActivity(intent3);

			Toast.makeText(this, "나의 꿈 등록 하기", Toast.LENGTH_SHORT).show();
			return true;

		case 4 :
			Intent intent4= new Intent(getApplicationContext(), DreamMap.class);
			startActivity(intent4);

			Toast.makeText(this, "나의 꿈 지도 보기", Toast.LENGTH_SHORT).show();
			return true;

		}
		return false;

	}

}
